package com.office.sysManage.roleManage.controller;


import com.office.sysManage.deptManage.pojo.Dept;
import com.office.sysManage.roleManage.pojo.Role;
import com.office.sysManage.roleManage.pojo.RoleAndLimits;
import com.office.sysManage.roleManage.service.impl.RoleServiceImpl;
import com.office.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 88168
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleServiceImpl roleService;

    public RoleServiceImpl getRoleService() {
        return roleService;
    }
    public void setRoleService(RoleServiceImpl roleService) {
        this.roleService = roleService;
    }


    /**
     * 根据查询条件查询角色信息
     * @param role 角色和权限对象
     * @return 角色集合
     */
    @ResponseBody
    @RequestMapping("/queryRolesByCondition")
    public List<Role> queryRolesByCondition(RoleAndLimits role) {
        if (role != null){
            return roleService.queryRolesByCondition(role);
        }
        return null;
    }

    /**
     * 添加角色
     * @param role 角色和权限对象
     * @return 是否添加成功
     */
    @ResponseBody
    @RequestMapping("/addRole")
    public boolean addRole(@RequestBody Role role) {
        if (role != null){
            return roleService.addRole(role);
        }
        return false;
    }

    /**
     * 添加角色权限
     * @param role 角色和权限对象
     * @return 是否添加成功
     */
    @RequestMapping("/addRoleLimit")
    public boolean addRoleLimit(RoleAndLimits role) {
        if (role != null){
            return roleService.addRoleLimit(role);
        }
        return false;
    }

    /**
     * 修改角色权限
     * @param role 角色和权限对象
     * @return 是否修改成功
     */
    @RequestMapping("/updateRoleAndLimit")
    public boolean updateRoleAndLimit(@RequestBody Role role) {
        if (role != null){
            return roleService.updateRoleAndLimit(role);
        }
        return false;
    }

    /**
     *
     * @param role 角色对象
     * @return 是否删除成功
     */
    @RequestMapping("/deleteRole")
    public boolean deleteRole(Role role) {
        if (role != null){
            return roleService.deleteRole(role);
        }
        return false;
    }

    /**
     * 根据角色名称查询角色信息
     * @param role 角色对象
     * @return 角色对象
     */
    @ResponseBody
    @RequestMapping("/queryRoleInfo")
    public Role queryRoleInfo(@RequestBody Role role) {
        return roleService.queryRoleInfo(role);
    }



}


